﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;

namespace TSB.FarmPowerShellWizard.Repository
{
    public class MMServiceRepository
    {

        public string GetDatabaseName(string serviceName)
        {
            var dbService = SPFarm.Local.Services.GetValue<SPDatabaseService>();
            var databaseName = string.Empty;
            foreach (SPDatabaseServiceInstance instance in dbService.Instances)
            {
                if (instance.Status == SPObjectStatus.Online)
                {
                    foreach (var database in instance.Databases)
                    {
                        object oDB = database.GetType();
                        if (oDB.ToString() == "Microsoft.SharePoint.Taxonomy.MetadataWebServiceDatabase")
                        {
                            
                            if (database.Name == serviceName)
                            {
                                databaseName = database.Name;

                            }
                        }
                    }
                }
            }

            return databaseName;

        }
    }
}
